Page({
    data: {
        categories: [],
        prices: [],
        activeCategory: 0,
        notices: []
    },

    onLoad() {
        this.loadMockData()
    },

    loadMockData() {
        // 模拟品类数据
        const mockCategories = [
            { id: 1, name: '金属类' },
            { id: 2, name: '塑料类' },
            { id: 3, name: '纸张类' },
            { id: 4, name: '家电类' }
        ]

        // 模拟价格公告
        const mockNotices = [
            {
                id: 1,
                title: '价格调整通知',
                content: '近期金属类回收价格有所上涨',
                effective_date: '2023-06-01'
            }
        ]

        this.setData({
            categories: mockCategories,
            notices: mockNotices
        }, () => {
            this.loadPrices()
        })
    },

    loadPrices() {
        // 模拟价格数据
        const priceData = {
            1: [
                { id: 101, name: '废铜', price: 45.8, unit: 'kg', min_price: 42.0, max_price: 48.0 },
                { id: 102, name: '废铝', price: 12.5, unit: 'kg', min_price: 11.0, max_price: 13.5 }
            ],
            2: [
                { id: 201, name: 'PET塑料', price: 3.2, unit: 'kg', min_price: 2.8, max_price: 3.5 },
                { id: 202, name: 'HDPE塑料', price: 2.8, unit: 'kg', min_price: 2.5, max_price: 3.0 }
            ],
            3: [
                { id: 301, name: '纸板', price: 1.2, unit: 'kg', min_price: 1.0, max_price: 1.3 },
                { id: 302, name: '报纸', price: 1.5, unit: 'kg', min_price: 1.3, max_price: 1.6 }
            ],
            4: [
                { id: 401, name: '电视机', price: 80, unit: '台', min_price: 60, max_price: 100 },
                { id: 402, name: '冰箱', price: 120, unit: '台', min_price: 100, max_price: 150 }
            ]
        }

        const { categories, activeCategory } = this.data
        const categoryId = categories[activeCategory]?.id
        this.setData({
            prices: priceData[categoryId] || []
        })
    },

    handleCategoryChange(e) {
        this.setData({
            activeCategory: e.detail.name
        }, () => {
            this.loadPrices()
        })
    },

    navigateToOrder() {
        wx.navigateTo({
            url: '/pages/order/order'
        })
    }
})